package concurrency.chapter3;

/**
 * 1、构造函数Thread()，创建线程对象Thread，默认有一个线程名，以Thread-开头，从0开始计数，如Thread-0
 * 2、Thread(Runnable target)，如果在构造Thread的时候，没有传Runnable参数，或者没有复写run()方法，该Thread将不会调用任何代码
 *
 *
 */
public class CreateThread {
    //main线程由jvm创建
    public static void main(String[] args) {
        //thread在start()时才会创建线程，init()方法
        Thread thread = new Thread();
        thread.start();
        System.out.println(thread.getName());

        Thread t2 = new Thread() {
            @Override
            public void run() {
                System.out.println("=====");
            }
        };
        t2.start();
        System.out.println(t2.getName());

        Thread t3=new Thread("Myname");
        Thread t4=new Thread(()->{
            System.out.println("Runnable");
        });
        System.out.println(t3.getName());
        System.out.println(t4.getName());

        Thread t5=new Thread(()->{
            System.out.println("Runnable..." +Thread.currentThread().getName());
        },"RunnableThread");
        t5.start();
    }
}
